import requests


class ApprovalRequest:

    def __init__(self, cookie):
        self.headers = {
            "Host": "app.work.weixin.qq.com",
            "charset": "utf-8",
            "accept-language": "zh-CN",
            "cookie": cookie,
            'User-Agent': "Mozilla/5.0 (Linux; Android 9; V1938CT Build/PQ3A.190705.003; wv) AppleWebKit/537.36 (KHTML, "
                          "like Gecko) Version/4.0 Chrome/91.0.4472.114 Safari/537.36 MMWEBID/658 wxwork/4.0.16.19901 "
                          "MicroMessenger/8.0.7.48(0x28000730) MiniProgramEnv/android Luggage/2.1.0.baa1bde8 NetType/WIFI "
                          "Language/zh_CN ABI/arm64",
            "content-type": "application/json",
            "Referer": "https://servicewechat.com/wx403094a4d093a136/23472/page-frame.html",
        }

    def get_templatelist(self):
        url = "https://app.work.weixin.qq.com/wework_admin/approval/api/get_template_list?limit=24&last_templateid=&page_from=xcx_home&filter=&recentlyUsedLimit=3"
        r = requests.get(url, headers=self.headers, verify=False)
        return r

    def get_templatesearch(self, keywords):
        url = "https://app.work.weixin.qq.com/wework_admin/approval/api/templateSearch"
        json = {
            "keywords": keywords
        }
        r = requests.post(url, headers=self.headers, json=json, verify=False)
        return r


